﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Security.Cryptography;
using System.Text;

namespace wuliuback
{
    public partial class QueryGoods : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string goodsId = Request["goods_id"];
            string pageNo = Request["page_no"];
            string pageSize=Request["page_size"];

            string code = "";
            string msg = "";
            string totalCount = "0";
            string goods = "";

            String sql = "";
            DbHelper dbHelper = new DbHelper();
            
            if (goodsId!=null&&goodsId.Length>0)
            {
                sql = "select *,1 as type from t_goods where goods_id=" + goodsId + " and status >-1 ";
            }
            else
            {
                sql = "select count(*) from t_goods where status= 1 order by created_time desc";
                DataSet dataSet = dbHelper.Select(sql);
                DataTable table = dataSet.Tables[0];
                if (table.Rows.Count > 0)
                {
                    totalCount = table.Rows[0].ToString();
                }
                sql = "select * from t_goods where status= 1 order by created_time desc";
            }

            DataSet dataSet1 = dbHelper.Select(sql);
            DataTable table1 = dataSet1.Tables[0];
            
            code = "0";
            goods = JsonUtil.DataTableToJson(table1);

            Response.Output.WriteLine("{\"code\":\"" + code + "\",\"msg\":\"" + msg
                                    + "\",\"page_no\":\"" + pageNo + "\",\"page_size\":\"" + pageSize + "\",\"total_count\":\"" + totalCount + "\",\"goods\":" + goods + "}");
        }
    }
}
